// pages/bprecord/bprecord.js
var app = new getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ischecked: null,
    bparr: [],
    allGoodsFilte: []
  },
  checkboxChange: function (e) {
    console.log(e)
    var allGoodsFilte = this.data.allGoodsFilte;
    var checkArr = e.detail.value;
    for (var i = 0; i < allGoodsFilte.length; i++) {
      if (checkArr.indexOf(allGoodsFilte[i].backpack_id) != -1) {
        allGoodsFilte[i]['checked'] = true;
      } else {
        allGoodsFilte[i]['checked'] = false;
      }
    }
    this.setData({
      allGoodsFilte: allGoodsFilte
    })
    app.backpack_record.backpack_order=e.detail.value;
  },
  orderTo:function(){
    if (app.backpack_record.backpack_order.length!=0){
      wx.navigateTo({
        url: '/pages/myorder_details/myorder_details'
      })
    }else{
      wx.showToast({
        title: '请选择宝贝',
        image: '/pages/images/err.png?v=1',
        duration: 2000
      })
    }
    
  },
  exchangegoldTo:function(){
    if (app.backpack_record.backpack_order.length != 0) {
      wx.navigateTo({
        url: '/pages/exchangegold/exchangegold'
      })
    } else {
      wx.showToast({
        title: '请选择宝贝',
        image: '/pages/images/err.png?v=1',
        duration: 2000
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.globalData.api_url + "/OpenAPI/V1/Backpack/getAll",
      data: {
        token: app.user.token,
        page: 1
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        var list = res.data.data.list;
        for (var i = 0; i < list.length; i++) {
          list[i]['checked'] = false
        }
        that.setData({
          allGoodsFilte: list
        })
      },
      fail: function (res) {
        console.log(res.data)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})